home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 1.0 beta / flock-1.0RC3.en-US.win32.exe / flock / components / flockFlockHandler.js < prev    next >
Text File  |  2007-10-18  |  5KB  |  162 lines

  1. // BEGIN FLOCK GPL
  2. // 
  3. // Copyright Flock Inc. 2005-2007
  4. // http://flock.com
  5. // 
  6. // This file may be used under the terms of of the
  7. // GNU General Public License Version 2 or later (the "GPL"),
  8. // http://www.gnu.org/licenses/gpl.html
  9. // 
  10. // Software distributed under the License is distributed on an "AS IS" basis,
  11. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. // for the specific language governing rights and limitations under the
  13. // License.
  14. // 
  15. // END FLOCK GPL
  16.  
  17. const CLASS_ID                = Components.ID("{7214FC64-FDA0-4DCD-B790-146265F8FA42}");
  18. const CLASS_NAME              = "Flock Protocol Handler";
  19. const CONTRACT_ID             = "@mozilla.org/network/protocol;1?name=flock";
  20.  
  21. function flockFlockHandler()
  22. {
  23. }
  24.  
  25. flockFlockHandler.prototype = {
  26.  
  27.   scheme: "flock",
  28.   defaultPort: -1,
  29.   protocolFlags: Components.interfaces.nsIProtocolHandler.URI_NORELATIVE | Components.interfaces.nsIProtocolHandler.URI_NOAUTH,
  30.   
  31.   allowPort: function(port, scheme)
  32.   {
  33.     return false;
  34.   },
  35.   
  36.   newChannel: function(URI)
  37.   {
  38.     var url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIStandardURL);
  39.     url.init(Components.interfaces.nsIStandardURL.URLTYPE_STANDARD, -1, URI.spec, null, null);
  40.     url.QueryInterface(Components.interfaces.nsIURL);
  41.     
  42.     switch (url.host) {
  43.       case "favorites":
  44.         var chromeURL = "chrome://flock/content/common/streamReader.xhtml";
  45.         break;
  46.       case "preview":
  47.         var chromeURL = "chrome://flock/content/common/streamReader.xhtml";
  48.         break;
  49.       default:
  50.         var chromeURL = "chrome://flock/content/common/streamReader.xhtml";
  51.         break;
  52.     }
  53.     
  54.     var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  55.     var channel = ios.newChannel(chromeURL, null, null);
  56.     
  57.     //var Channel = Components.Constructor("@flock.com/flock-channel;1", "flockIFlockChannel", "init");
  58.     //var channel = new Channel(URI);
  59.     
  60.     return channel;
  61.   },
  62.   
  63.   newURI: function(spec, originCharset, baseURI)
  64.   {
  65.     var url = Components.classes["@mozilla.org/network/simple-uri;1"].createInstance(Components.interfaces.nsIURI);
  66.  
  67.     try {
  68.       url.spec = spec;
  69.     } catch (e) {
  70.       try {
  71.         url.spec = this.scheme + ":" + spec;
  72.       } catch (e) {
  73.         url.spec = "javascript:void(0)";
  74.       }
  75.     }
  76.  
  77.     return url;
  78.   },
  79.  
  80.   // nsIClassInfo
  81.   getInterfaces: function(aCount)
  82.   {
  83.     var interfaces = [Components.interfaces.nsIProtocolHandler, Components.interfaces.nsIClassInfo];
  84.     aCount.value = interfaces.length;
  85.     return interfaces;
  86.   },
  87.  
  88.   // nsIClassInfo
  89.   getHelperForLanguage: function(aLanguage)
  90.   {
  91.     return null;
  92.   },
  93.  
  94.   // nsIClassInfo
  95.   contractID: CONTRACT_ID,
  96.  
  97.   // nsIClassInfo
  98.   classDescription: CLASS_NAME,
  99.  
  100.   // nsIClassInfo
  101.   classID: CLASS_ID,
  102.  
  103.   // nsIClassInfo
  104.   implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
  105.  
  106.   // nsIClassInfo
  107.   flags: null,
  108.   
  109.   // nsISupports
  110.   QueryInterface: function(aIID)
  111.   {
  112.     if (!aIID.equals(Components.interfaces.nsISupports) && !aIID.equals(Components.interfaces.nsIProtocolHandler) && !aIID.equals(Components.interfaces.nsIClassInfo))
  113.       throw Components.results.NS_ERROR_NO_INTERFACE;
  114.     return this;
  115.   }
  116.  
  117. };
  118.  
  119. /******************************************************************************
  120.  * XPCOM Functions for construction and registration
  121.  ******************************************************************************/
  122. var Module = {
  123.   _firstTime: true,
  124.   registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  125.   {
  126.     if (this._firstTime) {
  127.       this._firstTime = false;
  128.       throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  129.     }
  130.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  131.     aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  132.   },
  133.  
  134.   unregisterSelf: function(aCompMgr, aLocation, aType)
  135.   {
  136.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  137.     aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
  138.   },
  139.   
  140.   getClassObject: function(aCompMgr, aCID, aIID)
  141.   {
  142.     if (!aIID.equals(Components.interfaces.nsIFactory))
  143.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  144.     if (aCID.equals(CLASS_ID))
  145.       return Factory;
  146.     throw Components.results.NS_ERROR_NO_INTERFACE;
  147.   },
  148.  
  149.   canUnload: function(aCompMgr) { return true; }
  150. };
  151.  
  152. var Factory = {
  153.   createInstance: function(aOuter, aIID)
  154.   {
  155.     if (aOuter != null)
  156.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  157.     return (new flockFlockHandler()).QueryInterface(aIID);
  158.   }
  159. };
  160.  
  161. function NSGetModule(aCompMgr, aFileSpec) { return Module; }
  162.